package cn.kgc.service.impl;

import cn.kgc.dao.NewsCategoryDao;
import cn.kgc.dao.NewsDao;
import cn.kgc.dao.impl.NewsCategoryDaoImpl;
import cn.kgc.dao.impl.NewsDaoImpl;
import cn.kgc.pojo.NewsCategory;
import cn.kgc.service.NewsCategoryService;

public class NewsCategoryServiceImpl implements NewsCategoryService{
    private NewsDao newsDao;
    private NewsCategoryDao newsCategoryDao;

    public NewsCategoryServiceImpl(){
        newsDao = new NewsDaoImpl();
        newsCategoryDao = new NewsCategoryDaoImpl();
    }

    //删除新闻分类
    public boolean deleteNewsCategory(NewsCategory newsCategory) {
        boolean flag = false;
        int count = newsDao.getCountByCategory(newsCategory);
        if(count>0){
            System.out.println("无法删除新闻类别，该分类下还有新闻呢！");
        }else {
            flag = newsCategoryDao.deleteNewsCategory(newsCategory);
        }
        return flag;
    }

    public NewsCategory getNewsCategoryById(int id) {
        return newsCategoryDao.getNewsCategoryById(id);
    }
}
